/*
This file is part of vlc-remote.

vlc-remote is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

vlc-remote is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with vlc-remote.  If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 1.1

Rectangle {
    id: pageHeader
    signal clicked()
    signal doubleClicked()
    property alias title: textTitle.text
    property alias subtitle: textSubTitle.text
    property alias icon: iconType.source
    property real oldOpacity: 1.0
    anchors.top: parent.top
    width: parent.width
    height: 56
    color: accentColor
    //opacity: 0.75
    z: 12

    Column {
        spacing: 0
        Row {
            Text {
                id: textTitle
                anchors.leftMargin: 12
                width: pageHeader.width - 36
                font.pixelSize: 44
                font.letterSpacing: -3
                font.bold: false
                horizontalAlignment: Text.AlignLeft
                color: "white"
            }
            Image {
                id: iconType
                sourceSize.height: 36
                sourceSize.width: 36
                height: 36
                width: 36
                y: 0
                x: pageHeader.width - 32
                opacity: 0.5
            }
        }
        Row {
            Text {
                id: textSubTitle
                x: 0
                y: -10
                width: pageHeader.width - 4
                font.pixelSize: 16
                font.letterSpacing: -1
                font.italic: true
                anchors.rightMargin: 4
                horizontalAlignment: Text.AlignRight
                color: "white"
            }
        }
        Row {
            Rectangle {
                id: notifications
                visible: false
                width: pageHeader.width
                height:  txtNotificaton.height + 28
                color: "black"
                border.width: 2
                border.color: accentColor
                radius:  8
                z: 24
                y: -12
                Text {
                    id: txtNotificaton
                    text: ""
                    x: 8
                    width: notifications.width - 16
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.margins: 8
                    font.pixelSize: 26
                    font.letterSpacing: -1
                    font.bold: false
                    horizontalAlignment: Text.AlignLeft
                    color: accentColor
                    maximumLineCount: 3
                    wrapMode: "WrapAtWordBoundaryOrAnywhere"
                }

            }
        }
    }

    Timer {
        id: timerNotificationClose
        running: false
        triggeredOnStart: false
        onTriggered: {
            notifications.visible = false;
            timerNotificationClose.running = false;
        }
    }

    function notify(txt, timeout) {
        txtNotificaton.text = txt;
        notifications.visible = true;
        timerNotificationClose.stop();
        timerNotificationClose.interval = timeout;
        timerNotificationClose.start();
        //timerNotificationClose.running = true;
    }

    MouseArea {
        anchors.fill: parent
        onClicked: pageHeader.clicked()
        onDoubleClicked: pageHeader.doubleClicked()
        onEntered: { oldOpacity = pageHeader.opacity; pageHeader.opacity = oldOpacity - 0.25;  iconType.opacity = 1.0; }
        onExited: { pageHeader.opacity = oldOpacity; iconType.opacity = 0.5; }
    }
}
